cmake_minimum_required(VERSION 3.8)
project(demo_cpp_tf)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(auto_aim_interfaces REQUIRED)
find_package(tf2 REQUIRED)
find_package(angles REQUIRED)
find_package(Eigen3 REQUIRED)

# 设置包含目录
include_directories(
  ${Eigen3_INCLUDE_DIRS}
)

add_library(kalman_filter
  src/simple_kalman_filter.cpp
)

target_include_directories(kalman_filter PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
  ${Eigen3_INCLUDE_DIRS}
)

add_executable(dynamic_tf_broadcaster src/dynamic_tf_broadcaster.cpp)
add_executable(serial_node src/serial.cpp)

target_link_libraries(serial_node
  ${rclcpp_LIBRARIES}
  ${auto_aim_interfaces_LIBRARIES}
  ${angles_LIBRARIES}
  ${tf2_ros_LIBRARIES}
  ${tf2_geometry_msgs_LIBRARIES}
  ${geometry_msgs_LIBRARIES}
  Eigen3::Eigen  # <--- 链接Eigen库
  kalman_filter
)

ament_target_dependencies(dynamic_tf_broadcaster 
    rclcpp 
    tf2_ros 
    tf2_geometry_msgs 
    geometry_msgs
)
ament_target_dependencies(serial_node
   rclcpp 
   auto_aim_interfaces 
   angles 
   tf2 
   tf2_ros 
   tf2_geometry_msgs 
   geometry_msgs
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

install(TARGETS
        dynamic_tf_broadcaster
        serial_node
        DESTINATION lib/${PROJECT_NAME})

install(DIRECTORY 
        include/
        DESTINATION include
      )

install(DIRECTORY
        launch
        DESTINATION share/${PROJECT_NAME}
        )

ament_package()
